package com.yitianyigexiangfa.redis.startup.start;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author Bill Lau
 * @date 2017-11-24
 */
public class JedisStaticPool {

    private static JedisPool pool = null;

    public static JedisPool getPool(){
        if(pool == null){
            JedisPoolConfig config = new JedisPoolConfig();
            config.setMaxTotal(500);
            config.setMaxIdle(5);
            config.setMaxWaitMillis(1000 * 10);
            config.setTestOnBorrow(true);
            pool = new JedisPool(config, "127.0.0.1", 7000, 10000);
        }
        return pool;
    }

    public synchronized static Jedis getResource(){
        if (pool == null){
            pool = getPool();
        }
        return pool.getResource();
    }

}
